import type { IResCategoryData } from '@/types/categoryList'
import type { IResGoodsDetailData } from '@/types/goodsDetail'
import { httpMI } from '@/utils/requestMI'
import { httpYX } from '@/utils/requestYX'
/**
 * @description 获取一级分类列表数据
 * @returns
 */
export const reqCategory = () => {
  return httpYX<IResCategoryData>('/item/cateList.json', 'GET')
}

/**
 * @description 获取二级分类列表数据
 * @param id
 * @returns
 */
export const reqCategory2Data = (id: any) => {
  return httpYX<IResCategoryData>(
    `/item/cateList.json?__timestamp=1630131455012&categoryId=${id}`,
    'GET'
  )
}

/**
 * @description 获取某个分类下的商品列表
 * @param id
 * @param superId
 * @returns
 */
export const reqGoodsList = (id: any, superId: any) => {
  return httpYX<IResCategoryData>(
    `/item/list.json?subCategoryId=${id}&categoryId=${superId}`,
    'GET'
  )
}

/**
 * @description 获取商品详情
 * @param id
 * @returns
 */
export const reqGoodsDetail = (id: any) => {
  return httpMI<IResGoodsDetailData>(`/api/item/${id}`, 'GET')
}

/**
 * @description 加入购物车
 * @param id
 * @param num
 * @returns
 */
export const reqAddCart = (id: any, num: any) => {
  return httpMI(`/api/cart/addToCart/${id}/${num}`, 'POST')
}
